﻿@using PNProject.Core;
@using PNProject.EF;
@model PNProject.EF.Product
@{
    ViewBag.Title = "Edit";
    Layout = "~/Views/Shared/AdminLayout.cshtml";
    int i = 0;
    var listAttach = ServerHelper.SplitFileName(Model.Images);
    List<Comment> cms = (List<Comment>)ViewData["cms"];
}

<div class="admin_head">
Thay đổi thông tin sản phẩm - dịch vụ
</div>


<div class="admin_content">


@using (Html.BeginForm("Edit", "AdminPS", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.ValidationSummary(true)
    <fieldset>
    @Html.HiddenFor(a=>a.ProductID)
    @Html.HiddenFor(a=>a.CategoryID)
    @Html.HiddenFor(a=>a.Lang)
    @Html.HiddenFor(a=>a.ShortDesc)
    @Html.HiddenFor(a => a.AllowComment)
    @Html.HiddenFor(a => a.CategoryID)
    @Html.HiddenFor(a => a.Images)
        <legend>Form nhập - Sản phẩm dịch vụ</legend>
<div class="title">
<img src="/Images/Base/chimuc.jpg" style="margin-right:10px; margin-bottom:1px;"/>Ngôn ngữ
</div>
<div>
<select id="select_lang">
<option value="0">Tiếng Việt</option>
<option value="1">Tiếng Anh</option>
</select>
</div>
<br />
<div class="title">
<img src="/Images/Base/chimuc.jpg" style="margin-right:10px; margin-bottom:1px;"/>Tiêu đề
</div>
<div class="editor-field">
        @Html.EditorFor(model => model.Name)
</div>
<br />
<div class="title">
<img src="/Images/Base/chimuc.jpg" style="margin-right:10px; margin-bottom:1px;"/>Popup nội dung hiển thị khi rê chuột vào sản phẩm
</div>
<div class="editor-field">
        @Html.EditorFor(model => model.Slogan)
</div>
<br />
<div class="title">
<img src="/Images/Base/chimuc.jpg" style="margin-right:10px; margin-bottom:1px;"/>Tóm tắt
</div>
<textarea class="ckeditor" id="editor1" rows="10" style="width:540px; height:300px; overflow-x:hidden;"></textarea>
<br />

<div class="title">
<img src="/Images/Base/chimuc.jpg" style="margin-right:10px; margin-bottom:1px;"/>Hình đại diện
</div>
<img src="@Model.Avatar" height="100px" />
<br />
<div>
<input type="file" name="file" />
<div class="title">
Chọn hình từ internet
</div>
<div class="editor-field">
        @Html.EditorFor(model => model.Avatar)
</div>
</div>
<br />
<div id="attach_area">
@foreach (var item in listAttach)
{
<div class="attach_item"><span class="remove_attach" onclick="return confirmAction()">Xóa</span><img src="@item" height="100px" /></div>
}
</div>
<div class="title">
<img src="/Images/Base/chimuc.jpg" style="margin-right:10px; margin-bottom:1px;"/>Các hình đính kèm <br />
<input type="file" name="attach" />
</div>

<br />
<div class="title">
<img src="/Images/Base/chimuc.jpg" style="margin-right:10px; margin-bottom:1px;"/>Cho phép bình luận
</div>

<div>
<select id="select_allow">
<option value="0">Cho phép</option>
<option value="1">Không</option>
</select>
</div>

        <p>
            <input id="main-submit" type="submit" value="Cập nhật" />
        </p>
</fieldset>
}
<h2>Danh sách comments</h2>
@foreach (var item in cms)
{
    string name = string.IsNullOrEmpty(item.Username) ? item.Email : item.Username;
    name = name + " - " + item.SentDate.ToString();
    bool check = item.IsChecked.HasValue?item.IsChecked.Value:false;
    <div class="item-div">
    @if(check)
    {
    <img style="margin-right:10px; margin-bottom:-5px; width:15px; height:15px;" src="/Images/Base/check.png"/>
    }
    else
    {
    <img src="/Images/Base/chimuc.jpg" style="margin-right:10px; margin-bottom:1px;"/>
    }
    <a class="item-delete" href="/AdminPS/DeleteComment/@item.CommentID.ToString()">Xóa</a>
    <a class="item-link" href="/AdminPS/ViewComment/@item.CommentID.ToString()">@name</a>
    </div>
}
</div>
<script src="/Scripts/jquery-1.5.1.js" type="text/javascript"></script>
<script type="text/javascript">
    $(window).load(function () {
        CKEDITOR.instances['editor1'].setData($("#ShortDesc").val());
    });
    $(document).ready(function () {

        var lang = $("#Lang").val();
        if (lang == "True") {
            $("#select_lang").val("0");
        }
        else {
            $("#select_lang").val("1");
        }

        var allow = $("#AllowComment").val();
        if (allow == "True") {
            $("#select_allow").val("0");
        }
        else {
            $("#select_allow").val("1");
        }
        $(".remove_attach").click(function (event) {
            var p = $(event.target).parent();
            $(p).remove();
        });


        $("#main-submit").click(function () {
            var value1 = CKEDITOR.instances['editor1'].getData();
            var lang = $(select_lang).val();
            if (lang == "0") {
                $("#Lang").val("True");
            }
            else {
                $("#Lang").val("False");
            }
            $("#ShortDesc").val(value1);
            var str = "";
            var attach = $(".attach_item");
            for (var i = 0; i < attach.length; i++) {
                var item = $(attach[i]).find("img").attr("src");
                str = str + item + "*$*";
            }

            $("#Images").val(str);
            var allow = $(select_allow).val();
            if (allow == "0") {
                $("#AllowComment").val("True");
            }
            else {
                $("#AllowComment").val("False");
            }
        });
    });


</script>